#!/usr/bin/env python

class DataRow(dict):
    
    def _get_table(self):
        return self.__table
    def _set_table(self, table):
        self.__table = table
        
    def _get_row_state(self):
        return self.__rowState
    def _set_row_state(self, rowState):
        self.__rowState = rowState
        
    def _get_original_values(self):
        return self.__originalValues
    
    table = property(_get_table, _set_table)
    row_state = property(_get_row_state, _set_row_state)
    original_values = property(_get_original_values)
    
    def __init__(self, table):
        self.__original_values = dict()
        self.table = table
        self.__rowState = DataRowState.Detached
        pass
    
    def __getitem__(self, key):
        if (key not in self):
            raise Exception()
        return super[key]
    
    def __setitem__(self, key, value):
        if (not self.table.schema.has_key(key)):
            raise KeyError()
        
        if (self.row_state == DataRowState.Unchanged):
            self.row_state = DataRowState.Modified
        
        #TODO: modify self.OriginalValues accordingly
        
        dict.__setitem__(self, key, value)

class DataRowState:
    Detached = "Detached"
    New = "New"
    Modified = "Modified"
    Unchanged = "Unchanged"
    Deleted = "Deleted"